package com.zhengdongzulin.zuke.app.main.mine

import com.lxj.androidktx.core.*
import com.zhengdongzulin.zuke.R
import com.zhengdongzulin.zuke.base.*
import com.zhengdongzulin.zuke.databinding.ZkActivityIdAuthBinding
import com.zhengdongzulin.zuke.ext.checkId
import com.zhengdongzulin.zuke.ext.contrast
import com.zhengdongzulin.zuke.ext.getTextZ


/**
 * jeff
 * 实名认证
 * 2021-03-27 17:50:47
 */
class ZKIdAuthActivity : BaseActivity<IdAuthVm, ZkActivityIdAuthBinding>() {

    override fun getLayoutResId(): Int = R.layout.zk_activity_id_auth

    override fun initVM(): IdAuthVm = getVM(IdAuthVm::class.java)

    override fun initView() {

    }

    override fun initData() {

    }

    override fun initListener() {
        mView.commit.setOnClickListener {
            if (!mView.card.checkId()) {
                toast("请输入正确的身份证号")
                return@setOnClickListener
            }
            if (!mView.name.contrast(2)) {
                toast("请输入正确的姓名")
                return@setOnClickListener
            }
            mViewModel.verify_id_card(name = mView.name.getTextZ(), idCard = mView.card.getTextZ())
        }
    }

    override fun startObserve() {
        mViewModel.verify_id_card.observe(this, androidx.lifecycle.Observer {
            toast("认证成功")
            mShareViewModel.userInfo.value!!.realStatus = 1
            val value = mShareViewModel.userInfo.value!!.toJson()
            sp().putString("userInfo", value)
            finish()
        })
        mViewModel.verify_id_card.state.observe(this, getObserver(mViewModel.verify_id_card))
    }

}